﻿#include <ctime>
#include <iostream>
#include <fstream>
using namespace std;

void bubble(int list[], int length) {
    while (length--) {
        bool swapp = false;
        for (int i = 0; i < length; i++) {
            if (list[i] > list[i + 1]) {
                swap(list[i], list[i + 1]);
                swapp = true;
            }
        }
        if (swapp == false) 
            break;
    }
}

void readfile(const char* filename, int a[], int length) {
    ifstream file(filename);
    for (int i = 0; i < length; i++)
        file >> a[i];
}

int main()
{
    #define LEN 5000
    int a[LEN];
    readfile("m1_sorted.txt", a, LEN);
    unsigned int t1 = clock(); 
    bubble(a, LEN);
    unsigned int t2 = clock(); 
    unsigned int t3 = t2 - t1; 
    cout << "m1_sorted " << t3 << " milliseconds" << endl;

    readfile("m2_reverse.txt", a, LEN);
    t1 = clock(); 
    bubble(a, LEN);
    t2 = clock(); 
    t3 = t2 - t1; 
    cout << "m2_reverse " << t3 << " milliseconds" << endl;

    readfile("m3_shuffle.txt", a, LEN);
    t1 = clock(); 
    bubble(a, LEN);
    t2 = clock();
    t3 = t2 - t1; 
    cout << "m3_shuffle " << t3 << " milliseconds" << endl;
    return 0;
}